import logging,yagmail
import os.path
import time
import pytest
from openpyxl.styles.builtins import title
import HTMLTestRunner_PY3


def Log1():
    log1=logging.basicConfig(level=logging.DEBUG,
                            format='%(levelname)s %(message)s %(asctime)s %(filename)s %(lineno)s')
    return log1

def Log2():
        log2 = logging.basicConfig(level=logging.DEBUG,
                                   format='%(levelname)s %(message)s %(asctime)s %(filename)s %(lineno)d',
                                   filename='logs/jiuxian.log',
                                   filemode='a+'
                                   )
        return log2

def Log3():
    logging.basicConfig(level=logging.DEBUG,
                        format='%(levelname)s %(message)s %(asctime)s %(filename)s %(lineno)d',
                        filename='logs/jiuxian.log',
                        filemode='a+'
                        )
    logger=logging.getLogger()
    ch=logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    fmt=logging.Formatter('%(levelname)s %(message)s %(asctime)s %(filename)s %(lineno)d')
    ch.setFormatter(fmt)
    logger.addHandler(ch)
    logger.info("这是一个INFO级别的日志，This is level=info logging")

def Log4():
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    currTime=time.strftime('%Y-%m-%d')
    log_py_path=os.path.abspath(__file__)
    log_dir_path=os.path.split(log_py_path)[0]
    pro_path=os.path.dirname(log_dir_path)
    Log_path=pro_path + './'
    log_name=Log_path + currTime + '.log'
    fh=logging.FileHandler(log_name,mode='a')
    fh.setLevel(logging.INFO)
    fmt = logging.Formatter('%(levelname)s-%(message)s-%(asctime)s-%(filename)s-%(lineno)s')
    fh.setFormatter(fmt)
    logger.addHandler(fh)
    logger.info("这是一个INFO级别的日志，This is level=info logging")

def Report():
    report1=HTMLTestRunner_PY3.HTMLTestRunner(open('./Lx/plwrightpy126.py','wb'),
                                              title='126测试报告',
                                              description='A3mall项目实现数据驱动'
                                              )

def Email():
    email=yagmail.SMTP(user='1847537889@qq.com',password='liavbivsorckhacj',host='smtp.qq.com',port=465)
    email.send(to='1522057104@qq.com',subject="A3mall.0.3版本测试结果",contents=['执行了五条用例，均通过测试'])

if __name__ == '__main__':
    # Tools().Email()
    # pytest.main(
    #     [r'D:\gao1\PythonProject4\Zsd\pytestb.py', '-s', '--html=pybaogaao.html'])

    # pytest.main(
    #     [r'D:\gao1\PythonProject4\Lx\unittestc.py', '-s', '--html=unbaogaao.html'])

    pytest.main([r'D:\gao1\PythonProject4\Zsd\pytestb.py', '-s', '--allure=allure-results','--clean-alluredir'])
    os.system('allure generate allure-results -o allure-report --clean')